package com.zsrt.java.day20161226.wrl.day161226.demo14;

import java.util.Scanner;

import com.zsrt.java.day20161226.wrl.day161226.demo12.ArrayUtil;

/**
 * 输入一个不大于5位的整数，然后判断它是几位数，打印出各位数，并逆序输出个位数  1<=number<=99999
 *   1 	  <= n <10		1	 5			5	
 *   10   <= n <100		2	 23			32
 *   100  <= n <1000	3	 234		432
 *   1000 <= n <10000	4	 2345		5432
 *  10000 <= n <100000	5	 23456		65432
 * 
 * @author Administrator
 *
 */
public class Demo02 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个不大于5位的整数：1<= number <=99999");
		int num = input.nextInt();				//1 让用户从键盘上上输入一个数字
		if (num/10000>=1) {						//2 用/ 求整数，确定位数	
			System.out.println("...5位数...");
			printNumber(wanwei(num),qianwei(num),baiwei(num),shiwei(num),gewei(num));
		}else if (num/1000>=1) {
			System.out.println("...4位数...");
			printNumber(qianwei(num),baiwei(num),shiwei(num),gewei(num));
		}else if (num/100>=1) {
			System.out.println("...3位数...");
			printNumber(baiwei(num),shiwei(num),gewei(num));
		}else if (num/10>=1) {
			System.out.println("...2位数...");
			printNumber(shiwei(num),gewei(num));
		}else{
			System.out.println("...1位数...");
			printNumber(gewei(num));
		}
		input.close();
	}

	/**
	 * 使用可变形参，简化代码
	 * @param arrs	可变形参
	 */
	public static void printNumber(int... arrs) {		
		//把该数字的各位数字析出并存放到数组中
		int[] arrays = new int[arrs.length];
		for (int i = 0; i <= arrs.length-1; i++) {
			arrays[i] = arrs[i];
		}		
		System.out.println("\n顺序打印...");
		ArrayUtil.printArray(arrays);
		System.out.println("\n逆序打印...");
		ArrayUtil.printReverseArray(arrays);
	}

	/**
	 * 析出个位数字
	 * @param num	输入的数
	 * @return	个位数字
	 */
	public static int gewei(int num) {
		int g = num%10;
		return g;
	}
	/**
	 * 析出十位数字
	 * @param num	输入的数
	 * @return	十位数字
	 */
	public static int shiwei(int num) {
		int s = num%100/10;
		return s;
	}
	/**
	 * 析出百位数字
	 * @param num	输入的数
	 * @return	百位数字
	 */
	public static int baiwei(int num) {
		int b = num%1000/100;
		return b;
	}
	/**
	 * 析出千位数字
	 * @param num	输入的数
	 * @return	千位数字
	 */
	public static int qianwei(int num) {
		int q = num%10000/1000;
		return q;
	}
	/**
	 * 析出万位数字
	 * @param num	输入的数
	 * @return	万位数字
	 */
	public static int wanwei(int num) {
		int w = num/10000;
		return w;
	}

}
